package com.spring.sunflower.conversation

import com.spring.sunflower.base.BaseObserver
import com.spring.sunflower.base.BasePresenter
import com.spring.sunflower.bean.AnchorDetailBean
import com.spring.sunflower.bean.ChatGiftBean
import com.spring.sunflower.bean.GiveGiftBean

/**
 * Created by Kevin on 2021/7/31<br/>
 *
 * Describe:<br/>
 */
class GiftPresenter(baseView: ConversationContract.GiftView) :
    BasePresenter<ConversationContract.GiftView>(baseView) {
    fun loadAllGift() {
        val observable = requestDataSource.allGift
        addDisposable(observable, object : BaseObserver<ChatGiftBean>() {
            override fun onSuccess(bean: ChatGiftBean) {
                baseView.showGiftList(bean.datas)
            }

            override fun onError(status: Int, msg: String?) {
            }
        })
    }

    fun getDetail(userID: String) {
        val observable = requestDataSource.requestAnchorDetail(userID)
        addDisposable(observable, object : BaseObserver<AnchorDetailBean>() {
            override fun onSuccess(bean: AnchorDetailBean) {
                baseView.showAnchorData(bean.datas)
            }

            override fun onError(status: Int, msg: String?) {
            }
        })
    }

    fun sendGift(map: Map<String, String>, pos: Int) {
        val observable = requestDataSource.sendGift(map)
        addDisposable(observable, object : BaseObserver<GiveGiftBean>(baseView) {
            override fun onSuccess(bean: GiveGiftBean) {
//                baseView.showGiftList(bean.datas)
                baseView.sendGiftSuccess(bean.datas.data, pos)
            }

            override fun onError(status: Int, msg: String?) {
                baseView.sendGiftFailed("ErrCode:$status,msg:$msg")
            }
        })
    }
}